/*-----------------------------------------------------------------------------
	The contents of this file are subject to the Mozilla Public License
	Version 1.1 (the "License"); you may not use this file except in
	compliance with the License. You may obtain a copy of the License at
	http://www.mozilla.org/MPL/
	
	Software distributed under the License is distributed on an "AS IS"
	basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
	License for the specific language governing rights and limitations
	under the License.
	
	The Original Code is Fever Framework code.
	
	The Initial Developer of the Original Code is Romain Ecarnot.
	Portions created by Initial Developer are Copyright (C) 2006
	the Initial Developer. All Rights Reserved.
	
	Contributor(s):
	
	Unless required by applicable law or agreed to in writing, software
	distributed under the License is distributed on an "AS IS" BASIS,
	WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
	See the License for the specific language governing permissions and
	limitations under the License.
-----------------------------------------------------------------------------*/

import com.bourre.data.collections.Map;

import fever.app.accelerator.ShortcutMap;

/**
 * {@code ShortcutLocator } class.

 * <p>Example
 * {@code
 *   var map : ShortcutMap = ShortcutLocator.getMap( 'map1' );
 *   map.registerEvent( Keyboard.onKeyCONTROL, this, _onKey );
 *   map.registerCommand( Keyboard.onKeyADD, new CommandTest() );
 *   map.load();
 * }
 * 
 * @author Romain Ecarnot
 */
class fever.app.accelerator.ShortcutLocator extends ShortcutMap
{
	//-------------------------------------------------------------------------
	// Private properties
	//-------------------------------------------------------------------------
	
	private static var _m : Map = new Map();
	
		
	//-------------------------------------------------------------------------
	// Public API
	//-------------------------------------------------------------------------
	
	/**
	 * Returns {@link fever.app.accelerator.ShortcutMap} registred with 
	 * passed-in {@code mapName} identifier.<br />
	 * If map does not exist, creates it.
	 * 
	 * @param mapName A shortcut map identifier
	 * 
	 * @return Registred {@link fever.app.accelerator.ShortcutMap} map 
	 */
	public static function getMap( mapName : String ) : ShortcutMap
	{
		if( !_m.containsKey( mapName ) )
		{
			var map : ShortcutMap = new ShortcutMap( mapName );
			_m.put( map.getName(), map );
			return map;
		}
		else return _m.get( mapName );	
	}
	
	/**
	 * Returns {@code true} if a {@link  passed-in {@code mapName} is registred.
	 * 
	 * @param mapName A shortcut map identifier
	 * 
	 * @return {@code true} if shortcut is registred
	 */
	public static function isRegistered( mapName : String ) : Boolean
	{
		return _m.containsKey( mapName );
	}
	
	/**
	 * Unregisters {@link fever.app.accelerator.ShortcutMap} registred with 
	 * passed-in {@code mapName}.
	 * 
	 * <p>All shortcuts are disabled.
	 * 
	 * @param mapName A shortcut map identifier
	 */
	public function unregister( mapName : String ) : Void
	{
		if( _m.containsKey( mapName ) )
		{
			var map : ShortcutMap = _m.get( mapName );
			map._clear();
			_m.remove( mapName );
		}
	}
	
	
	//-------------------------------------------------------------------------
	// Private implementation
	//-------------------------------------------------------------------------
		
	/**
	 * Constructor.
	 */
	private function ShortcutLocator()
	{
		
	}	
}